<?php


// 应用公共文件
use app\common\SmsDemo;
use think\Loader;
use Qcloud\Sms\SmsSingleSender;
use Qcloud\Sms\SmsMultiSender;
use Qcloud\Sms\SmsVoiceVerifyCodeSender;
use Qcloud\Sms\SmsVoicePromptSender;
use Qcloud\Sms\SmsStatusPuller;
use Qcloud\Sms\SmsMobileStatusPuller;
/*函数排序*/

function replace_unicode_escape_sequence($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function array_sort($arr,$keys,$type='asc'){
    $keysvalue = $new_array = array();
    foreach ($arr as $k=>$v){
        $keysvalue[$k] = $v[$keys];
    }
    if($type == 'asc'){
        asort($keysvalue);
    }else{
        arsort($keysvalue);
    }
    reset($keysvalue);
    foreach ($keysvalue as $k=>$v){
        $new_array[$k] = $arr[$k];
    }
    return $new_array;
}
/*
 * crypt + md5 混淆加密
 * @param  string $pass 密码明文
 */
function mcs($pass)
{
    return md5(md5($pass));
}

/*
 * 截取字符串
 */
function subtext($text, $length, $end = '...')
{
    if (mb_strlen($text, 'utf8') > $length)
        return mb_substr($text, 0, $length, 'utf8') . $end;
    return $text;
}

/*
 * 获取用户真实 IP
 */
function getIP()
{
    static $realIp;
    if (isset($_SERVER)) {
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
            $realIp = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realIp = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realIp = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")) {
            $realIp = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realIp = getenv("HTTP_CLIENT_IP");
        } else {
            $realIp = getenv("REMOTE_ADDR");
        }
    }
    return $realIp;
}

/*
 * 成功提示函数
 * @param  string $msg 提示信息
 * @param  string $url 跳转地址
 * @param  integer $url 延时时间
 * @param  string $note 提示描述
 */
function win1($msg, $url, $time = 2333, $note = "页面跳转中")
{
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){location.href='$url'}};function delayURL(url,time){setTimeout(\"top.location.href='\" + url + \"'\",time)}</script>";
    abort(\think\Response::create($content, 'html'));
}

/*
 * 失败提示函数
 * @param  string $msg 提示信息
 * @param  integer $time 延时时间
 * @param  string $note 提示描述
 */
function fail($msg, $time = 2333, $note = "页面跳转中")
{
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;function myfun(){swal('$msg','$note','error');delayURL(3000);document.querySelector('.confirm').onclick=function(){window.history.back()}};function delayURL(time){setTimeout(\"window.history.back();\",$time)};</script>";
    abort(\think\Response::create($content, 'html'));
}


/*
 * 没有权限提示函数
 * @param  string $msg 提示信息
 * @param  integer $time 延时时间
 * @param  string $note 提示描述
 */
function auth_fail($msg, $url, $time = 2333, $note = "页面跳转中")
{
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','error');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){location.href='$url'}};function delayURL(url,time){setTimeout(\"top.location.href='\" + url + \"'\",time)}</script>";
    abort(\think\Response::create($content, 'html'));
}

function fen(){
    //return (new Area())->province_list();
    db('test')->insert(['content' => time()]);
}
/*
 * 图片上传
 * @param string $img 图片名称
 */
function uploadImg($img = 'picUrl', $type = 'thumb')
{
    $file = request()->file($img);
    if (!empty($file)) {

        // 移动到框架应用根目录/public/uploads/ 目录下
        $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');

        // halt($upload);
        if ($upload) {

            if ($type == 'thumb') {
                //图片处理
                imgDispose('public' . DS . 'uploads' . DS . $upload->getSaveName());
            }

            //返回图片地址
            return 'uploads/' . date('Ymd') . '/' . $upload->getFilename();
        }
        return $file->getError();
    }

    return request()->param($img);
}

/*
 * 图片处理
 * @param string $img 图片名称
 */
function imgDispose($img = '')
{
    // 水印
    if ('true' == cache('web_watermark')) {

        if (cache('web_marktype') == '1')
            \think\Image::open(ROOT_PATH . $img)->water(ROOT_PATH . 'public' . DS . 'uploads' . DS . 'thumb_watermarket.png', cache('web_markwhere'), cache('web_transparent'))->save(ROOT_PATH . $img);
        else
            \think\Image::open(ROOT_PATH . $img)->text(cache('web_marktext'), ROOT_PATH . 'public' . DS . 'uploads' . DS . 'simsun.ttc', cache('web_transparent'), '#' . cache('web_markcolor'), cache('web_markwhere'))->save(ROOT_PATH . $img);
    }

    // 缩略图
    if ('true' == cache('web_thumb')) {

        \think\Image::open(ROOT_PATH . $img)->thumb(cache('web_thumbwide'), cache('web_thumbhigh'))->save(ROOT_PATH . get_thumb_pic($img));
    }

}



/*
 * 缩略图处理
 * @param string $img 图片名称
 */
function get_thumb_pic($img)
{
    $path = explode('/', $img);
    $count = count($path);
    $path[$count - 1] = "thumb_" . $path[$count - 1];
    return implode('/', $path);
}

function show_thumb_pic($img)
{
    $path = explode('/', $img);
    $count = count($path);
    $path[$count - 1] = "thumb_" . $path[$count - 1];
    return implode('/', $path);
}

// 组图上传
function multi_upload()
{
    // 接受流
    $file = request()->file();
    //halt($file);
    //$a = $_FILES;
    //write_log($a);
    write_log($file);
    //write_log(halt($file));
    //halt($file);
    //halt(34124);
    $result = [];
    for ($i = 0; $i < count($file); $i++) {
        $info = $file[$i]->move(ROOT_PATH . 'public' . DS . 'uploads');
        //write_log('hah'.$info);
        $result[] = ['path' => 'uploads/' . date('Ymd') . '/' . $info->getFilename()];
    }

    //write_log('hah'.json_encode($result));
    //halt(1);
    //halt('g'.$result);
    if (empty($result)) return '';

    //halt(1);
    return serialize($result);
}

function write_log($data){
    $years = date('Y-m');
    //设置路径目录信息
    $url = './log/'.$years.'/'.date('Ymd').'_request_log.txt';
    $dir_name=dirname($url);
    //目录不存在就创建
    if(!file_exists($dir_name))
    {
        //iconv防止中文名乱码
        $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
    }
    $fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
    fwrite($fp,var_export($data,true)."\r\n");//写入文件
    fclose($fp);//关闭资源通道
}

/*
 * 数组分组
 *
 * @param object $data 二维数组
 * @param object $obj 对象
 */
function arrayGrouping($data, $val, $title, $list)
{
    if (empty($data)) return [];

    $result = array_values(array_reduce($data, function ($value, $key) use ($val, $title, $list) {
        $name = $key[$val];
        unset($key[$val]);
        $value[$name][$title] = $name;
        $value[$name][$list][] = $key;
        return $value;
    }));

    return $result;
}

/*
 * 一维数组 变成 二位数组
 *
 * @param object $data 一维数组
 * @param object $obj 名称
 */
function arrayChange($data, $title, $list)
{
    if (empty($data)) return [];
    $result = [];
    $n = 0;
    foreach ($data as $key => $value) {
        $result[$n][$title] = $key;
        $result[$n][$list] = array_values($value);
        $n++;
    }
    return $result;
}


/*
 * 递归节点
 * @param $multi 递归数组
 * @param int $parent_id 父级id
 * @return array
 */
function recursion_node($multi, $parent_id = 0, $name = 'classify', $variable = 'parenTid', $variable2 = 'id')
{

    if (empty($multi)) return false;
    $result = [];
    foreach ($multi as $item) {

        if ($item[$variable] == $parent_id) {

            $item[$name] = recursion_node($multi, $item[$variable2], $name, $variable, $variable2);


            if (empty($item[$name])) $item[$name] = [];
            $result[] = $item;
        }
    }

    return $result;
}

/*
 * 生成parentStr
 * @param $multi 生成parentStr
 * @param int $parenTid 父级id
 * @param int $id 条id
 * @param int $repId 上级id
 * @return array
 */
function parentStr($parenTid = '', $table = '', $id = '', $repId = '', $table2 = '')
{
    if (!empty($id))
        return \app\common\trilateral\Classify::UpParentStr($parenTid, $id, $repId, $table, $table2);
    else
        return \app\common\trilateral\Classify::GetParentStr($parenTid, $table);
}

/*
 * 生成count
 * @param $multi 生成count
 * @param int $parenTid 父级id
 * @param int $id 条id
 * @return array
 */
function ruleCount($parenTid = '', $table = '', $id = '')
{

    if (!empty($id))
        return \app\common\trilateral\Classify::countUpdate($id, $parenTid, $table);
    else
        return \app\common\trilateral\Classify::countAdd($parenTid, $table);
}

/*
 * 生成sku
 * @param $multi 生成sku
 * @param int $len 长度
 * @param int $sign 默认长度
 * @return array
 */
function SpecSku($len, $sign)
{
    if ($len < $sign) {
        echo "for (var i_" . $len . "=0; i_" . $len . "<spec_group_checked[" . $len . "].length; i_" . $len . "++){td_" . (intval($len) + 1) . " = spec_group_checked[" . $len . "][i_" . $len . "];\n";
        $len++;
        SpecSku($len, $sign);
    } else {
        echo "var tmp_spec_td = new Array();\n";
        for ($i = 0; $i < $len; $i++) {
            echo "tmp_spec_td[" . ($i) . "] = td_" . ($i + 1) . "[1];\n";
        }
        echo "tmp_spec_td.sort(function(a,b){return a-b});\n";
        echo "var spec_bunch = 'i_';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "spec_bunch += tmp_spec_td[" . ($i) . "];\n";
        }
        echo "str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][goods_id]\" nc_type=\"'+spec_bunch+'|goods_id\" value=\"\" />';";
        for ($i = 0; $i < $len; $i++) {
            echo "if (td_" . ($i + 1) . "[2] != null) { str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][color]\" value=\"'+td_" . ($i + 1) . "[1]+'\" />';}";
            echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][sp_value]['+td_" . ($i + 1) . "[1]+']\" value=\"'+td_" . ($i + 1) . "[0]+'\" />'+td_" . ($i + 1) . "[0]+'</td>';\n";
        }
        echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][id]\" nc_type=\"'+spec_bunch+'|id\" value=\"\" /><input class=\"text marketprice\" type=\"text\" name=\"spec['+spec_bunch+'][marketprice]\" data_type=\"marketprice\" nc_type=\"'+spec_bunch+'|marketprice\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text price\" type=\"text\" name=\"spec['+spec_bunch+'][price]\" data_type=\"price\" nc_type=\"'+spec_bunch+'|price\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][alarm]\" data_type=\"alarm\" nc_type=\"'+spec_bunch+'|alarm\" value=\"\" /></td><td><input class=\"text sku\" type=\"text\" name=\"spec['+spec_bunch+'][sku]\" nc_type=\"'+spec_bunch+'|sku\" value=\"\" /></td></tr>';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "}\n";
        }
    }
}

function SpecSku1($len, $sign)
{
    if ($len < $sign) {
        echo "for (var i_" . $len . "=0; i_" . $len . "<spec_group_checked[" . $len . "].length; i_" . $len . "++){td_" . (intval($len) + 1) . " = spec_group_checked[" . $len . "][i_" . $len . "];\n";
        $len++;
        SpecSku($len, $sign);
    } else {
        echo "var tmp_spec_td = new Array();\n";
        for ($i = 0; $i < $len; $i++) {
            echo "tmp_spec_td[" . ($i) . "] = td_" . ($i + 1) . "[1];\n";
        }
        echo "tmp_spec_td.sort(function(a,b){return a-b});\n";
        echo "var spec_bunch = 'i_';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "spec_bunch += tmp_spec_td[" . ($i) . "];\n";
        }
        echo "str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][goods_id]\" nc_type=\"'+spec_bunch+'|goods_id\" value=\"\" />';";
        for ($i = 0; $i < $len; $i++) {
            echo "if (td_" . ($i + 1) . "[2] != null) { str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][color]\" value=\"'+td_" . ($i + 1) . "[1]+'\" />';}";
            echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][sp_value]['+td_" . ($i + 1) . "[1]+']\" value=\"'+td_" . ($i + 1) . "[0]+'\" />'+td_" . ($i + 1) . "[0]+'</td>';\n";
        }
        echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][id]\" nc_type=\"'+spec_bunch+'|id\" value=\"\" /><input class=\"text marketprice\" type=\"text\" name=\"spec['+spec_bunch+'][marketprice]\" data_type=\"marketprice\" nc_type=\"'+spec_bunch+'|marketprice\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text price\" type=\"text\" name=\"spec['+spec_bunch+'][price]\" data_type=\"price\" nc_type=\"'+spec_bunch+'|price\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][alarm]\" data_type=\"alarm\" nc_type=\"'+spec_bunch+'|alarm\" value=\"\" /></td><td><input class=\"text sku\" type=\"text\" name=\"spec['+spec_bunch+'][sku]\" nc_type=\"'+spec_bunch+'|sku\" value=\"\" /></td></tr>';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "}\n";
        }
    }
}



// 字符串截取
function reStrLen($str, $len=10, $etc='...')
{
    $reStr = '';
    $i = 0;
    $n = 0.0;

    //字符串的字节数
    $strlen = strlen($str);
    while(($n < $len) and ($i < $strlen))
    {
        $temp_str = substr($str, $i, 1);

        //得到字符串中第$i位字符的ASCII码
        $ascnum = ord($temp_str);

        //如果ASCII位高与252
        if($ascnum >= 252)
        {
            //根据UTF-8编码规范，将6个连续的字符计为单个字符
            $reStr = $reStr.substr($str, $i, 6);
            //实际Byte计为6
            $i = $i + 6;
            //字串长度计1
            $n++;
        }
        else if($ascnum >= 248)
        {
            $reStr = $reStr.substr($str, $i, 5);
            $i = $i + 5;
            $n++;
        }
        else if($ascnum >= 240)
        {
            $reStr = $reStr.substr($str, $i, 4);
            $i = $i + 4;
            $n++;
        }
        else if($ascnum >= 224)
        {
            $reStr = $reStr.substr($str, $i, 3);
            $i = $i + 3 ;
            $n++;
        }
        else if ($ascnum >= 192)
        {
            $reStr = $reStr.substr($str, $i, 2);
            $i = $i + 2;
            $n++;
        }

        //如果是大写字母 I除外
        else if($ascnum>=65 and $ascnum<=90 and $ascnum!=73)
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，大写字母计成一个高位字符
            $n++;
        }

        //%,&,@,m,w 字符按1个字符宽
        else if(!(array_search($ascnum, array(37, 38, 64, 109 ,119)) === FALSE))
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，这些字条计成一个高位字符
            $n++;
        }

        //其他情况下，包括小写字母和半角标点符号
        else
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数计1个
            $i = $i + 1;
            //其余的小写字母和半角标点等与半个高位字符宽
            $n = $n + 0.5;
        }
    }

    //超过长度时在尾处加上省略号
    if($i < $strlen)
    {
        $reStr = $reStr.$etc;
    }

    return $reStr;
}

// 字符串截取
function str_len($str, $len=10, $etc='...')
{
    $reStr = '';
    $i = 0;
    $n = 0.0;

    //字符串的字节数
    $strlen = strlen($str);
    while(($n < $len) and ($i < $strlen))
    {
        $temp_str = substr($str, $i, 1);

        //得到字符串中第$i位字符的ASCII码
        $ascnum = ord($temp_str);

        //如果ASCII位高与252
        if($ascnum >= 252)
        {
            //根据UTF-8编码规范，将6个连续的字符计为单个字符
            $reStr = $reStr.substr($str, $i, 6);
            //实际Byte计为6
            $i = $i + 6;
            //字串长度计1
            $n++;
        }
        else if($ascnum >= 248)
        {
            $reStr = $reStr.substr($str, $i, 5);
            $i = $i + 5;
            $n++;
        }
        else if($ascnum >= 240)
        {
            $reStr = $reStr.substr($str, $i, 4);
            $i = $i + 4;
            $n++;
        }
        else if($ascnum >= 224)
        {
            $reStr = $reStr.substr($str, $i, 3);
            $i = $i + 3 ;
            $n++;
        }
        else if ($ascnum >= 192)
        {
            $reStr = $reStr.substr($str, $i, 2);
            $i = $i + 2;
            $n++;
        }

        //如果是大写字母 I除外
        else if($ascnum>=65 and $ascnum<=90 and $ascnum!=73)
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，大写字母计成一个高位字符
            $n++;
        }

        //%,&,@,m,w 字符按1个字符宽
        else if(!(array_search($ascnum, array(37, 38, 64, 109 ,119)) === FALSE))
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，这些字条计成一个高位字符
            $n++;
        }

        //其他情况下，包括小写字母和半角标点符号
        else
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数计1个
            $i = $i + 1;
            //其余的小写字母和半角标点等与半个高位字符宽
            $n = $n + 0.5;
        }
    }

    //超过长度时在尾处加上省略号
    if($i < $strlen)
    {
        $reStr = $reStr.$etc;
    }

    return $reStr;
}


function put_file_from_url_content($url, $saveName, $path) {
    // 设置运行时间为无限制
    set_time_limit ( 0 );

    $url = trim ( $url );
    $curl = curl_init ();
    // 设置你需要抓取的URL
    curl_setopt ( $curl, CURLOPT_URL, $url );
    // 设置header
    curl_setopt ( $curl, CURLOPT_HEADER, 0 );
    // 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
    curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
    // 运行cURL，请求网页
    $file = curl_exec ( $curl );
    // 关闭URL请求
    curl_close ( $curl );
    // 将文件写入获得的数据
    $filename = $path . $saveName;
    $write = @fopen ( $filename, "w" );
    if ($write == false) {
        return false;
    }
    if (fwrite ( $write, $file ) == false) {
        return false;
    }
    if (fclose ( $write ) == false) {
        return false;
    }


}


// 剩余时间
function gettime($time_s,$time_n){
    // $time_s = strtotime($time_s);
    // $time_n = strtotime($time_n);
    $strtime = '';
    $time = $time_n-$time_s;

    if($time >= 86400){
        return $strtime = date('Y-m-d H:i:s',$time_n);
    }
    if($time >= 3600){
        $strtime .= intval($time/3600).'小时';
        $time = $time % 3600;
    }else{
        $strtime .= '';
    }
    if($time >= 60){
        $strtime .= intval($time/60).'分钟';
        $time = $time % 60;
    }else{
        $strtime .= '';
    }
    if($time > 0){
        $strtime .= intval($time).'秒前';
    }else{
        $strtime = "时间错误";
    }
    return $strtime;
}

function sendSMSS($phone, $content)
{

    $yourAccessKeyId  = "LTAI9lQFD5Jf2l0h";
    $yourAccessKeySecret = "UJk2PhWFtFSHJqFIOACxfyzn1lM1AZ";
    $sms = new SmsDemo($yourAccessKeyId, $yourAccessKeySecret);

    $signName = "阿里云短信测试专用";
    $templateCode = "SMS_106000075";
    $code = array(
        "code"=>"【Ishop】".$content,
    );

    $response = $sms->sendSms($signName,$templateCode,$phone,$code);

    return $response;
}

function file_get_contents_post($url, $post){
//    $curl = curl_init();
// //设置抓取的url
//   curl_setopt($curl, CURLOPT_URL, $url);
//     //设置头文件的信息作为数据流输出
//     curl_setopt($curl, CURLOPT_HEADER, 1);
//      //设置获取的信息以文件流的形式返回，而不是直接输出。
//      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//      //设置post方式提交
//   curl_setopt($curl, CURLOPT_POST, 1);
//    //设置post数据
//     $post_data = $post;
//     curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//     //执行命令
//     $data = curl_exec($curl);
//     //关闭URL请求
//    curl_close($curl);
//     //显示获得的数据
//
//return $data;
    $options = array(CURLOPT_RETURNTRANSFER =>true,CURLOPT_HEADER =>false,CURLOPT_POST =>true,CURLOPT_POSTFIELDS => $post,);
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
};

function  curl_post1($url,$post){

    $options = array(CURLOPT_RETURNTRANSFER =>true,CURLOPT_HEADER =>false,CURLOPT_POST =>true,CURLOPT_POSTFIELDS => $post,);
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

function sendSMS($phone, $content)
{
    $yourAccessKeyId  = "LTAIrQfi5MFvwYAa";
    $yourAccessKeySecret = "mwNq9dskpNBu9gOj8t8IhP6snE1rxG";
    $sms = new SmsDemo($yourAccessKeyId, $yourAccessKeySecret);

    $signName = "善食元";
    $templateCode = "SMS_140915081";
    $code = array(
        "code"=> $content,
    );

    $response = $sms->sendSms($signName,$templateCode,$phone,$code);

    return $response;
}

function sendSMStxy($phone,$content){


    // 短信应用SDK AppID
    $appid = 1400092815; // 1400开头

// 短信应用SDK AppKey
    $appkey = "cb1af932861fab16fd1fda208453cb65";

// 需要发送短信的手机号码
    $phoneNumbers = [$phone, "12345678902", "12345678903"];

// 短信模板ID，需要在短信应用中申请
    $templateId = 7839;  // NOTE: 这里的模板ID`7839`只是一个示例，真实的模板ID需要在短信控制台中申请
    $params = [findNum($content),1];
// 签名
    $smsSign = "腾讯云"; // NOTE: 这里的签名只是示例，请使用真实的已申请的签名，签名参数使用的是`签名内容`，而不是`签名ID`
// 单发短信
    try {
        $ssender = new SmsSingleSender($appid, $appkey);
//        $result = $ssender->send(0, "86", $phoneNumbers[0],
//            findNum($content)."为您的验证码，请于1分钟内填写。如非本人操作，请忽略本短信。", "", "");
        $result = $ssender->sendWithParam(86, $phone, 122684, $params,
            "高原狼", "", "");

        $rsp = json_decode($result);
        //dump($rsp);
        if($rsp->result == 0) return 1;

    } catch(\Exception $e) {
        //return $e->getMessage();
       echo var_dump($e->getMessage());
    }
}

function findNum($str=''){
    $str=trim($str);
    if(empty($str)){return '';}
    $result='';
    for($i=0;$i<strlen($str);$i++){
        if(is_numeric($str[$i])){
            $result.=$str[$i];
        }
    }
    return $result;
}

